//
//  H5ViewController.m
//  h5demo
//
//  Created by 袁伟森 on 2019/3/14.
//  Copyright © 2019 Alibaba. All rights reserved.
//

#import "H5ViewController.h"
#import "MPWebView.h"
@interface H5ViewController ()<PSDPluginProtocol,UIWebViewDelegate,DTNavigationBarAppearanceProtocol>
@property (nonatomic , strong) AUCustomNavigationBar *navBar;
@end

@implementation H5ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
//    self.navigationController.navigationBar.barTintColor = [UIColor redColor];
//    self.title = @"123";
//    MPWebView *mv = [[MPWebView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
//    mv.backgroundColor = [UIColor orangeColor];
//    [self.view addSubview:mv];
    
//    self.view.backgroundColor = [UIColor whiteColor];
//    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor redColor]}];

    NSLog(@"打开一个容器  ");
    
//    [[NBServiceGet() appCenter] prepareApp:@"12345678" version:@"1.*" process:^(NAMAppPrepareStep step, id info) {
//        
//    } finish:^(NAMApp *app, NSError *error) {
//        if (!error) {
//            dispatch_async(dispatch_get_main_queue(), ^{
//                [NBServiceGet()  startSession:@{@"appId":@"12345678",@"version":@"1.*"}
//                                     animated:YES];
//                //, @"showOptionMenu":@"NO"
//            });
//        }
//        
//    }];
    
}
- (BOOL)autohideNavigationBar
{
    return YES;
}
- (UIView *)customNavigationBar
{
    return self.navBar;
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    UIWebView *webView = (UIWebView *)self.psdContentView;

    NSDictionary *dic = self.psdScene.createParam.expandParams;
    
//    UINavigationController *navBar = [[UINavigationController alloc] initWithNavigationBarClass:NSClassFromString(@"AUNavigationBar")  toolbarClass:nil];
//
//    [navBar.navigationBar setNavigationBarTitleTextAttributesWithTextColor:[UIColor blackColor]];
    
}
#pragma mark - 注册为容器插件
- (void)nbViewControllerInit
{
    PSDSession *session = [self viewControllerProxy].psdSession;
    [session addEventListener:kEvent_Navigation_All
                 withListener:self
                   useCapture:NO];
    [session addEventListener:kEvent_Page_All
                 withListener:self
                   useCapture:NO];
    
}

- (NSString *)name
{
    return NSStringFromClass([self class]);
}

- (void)handleEvent:(PSDEvent *)event
{
    if (![[event.context currentViewController] isEqual:self]) {
        return;
    }
    if ([kEvent_Navigation_Start isEqualToString:event.eventType]) {
        BOOL shouldStart = [self handleContentViewShouldStartLoad:(id)event ];
        
        if (!shouldStart) {
            [event preventDefault];
        }
    }
    else if ([kEvent_Page_Load_Start isEqualToString:event.eventType]) {
        [self handleContentViewDidStartLoad:(id)event];
    }
    else if ([kEvent_Page_Load_Complete isEqualToString:event.eventType]) {
        [self handleContentViewDidFinishLoad:(id)event];
    }
    else if ([kEvent_Navigation_Error isEqualToString:event.eventType]) {
        [self handleContentViewDidFailLoad:(id)event];
    }
    else if ([kNBEvent_Scene_NavigationItem_Left_Back_Click isEqualToString:event.eventType]) {
        
    }
}


- (BOOL)handleContentViewShouldStartLoad:(PSDNavigationEvent *)event
{
    return YES;
}

- (void)handleContentViewDidStartLoad:(PSDPageEvent *)event
{
    
}

- (void)handleContentViewDidFinishLoad:(PSDPageEvent *)event
{
    
}

- (void)handleContentViewDidFailLoad:(PSDNavigationEvent *)event
{
    
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
